package com.example.day03_32.model;

import android.util.Log;


import com.example.day03_32.base.BaseModel;
import com.example.day03_32.bean.NaviBean;
import com.example.day03_32.net.HttpUtil;
import com.example.day03_32.net.ResultCallBack;
import com.example.day03_32.net.ResultSubscriber;
import com.example.day03_32.net.RxUtils;
import com.example.day03_32.net.WanService;

import io.reactivex.Flowable;
import io.reactivex.Observable;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;
import io.reactivex.subscribers.ResourceSubscriber;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

public class MainModel extends BaseModel {
    public void getData(final ResultCallBack<NaviBean> callBack) {
        Retrofit build = new Retrofit.Builder()
                .baseUrl(WanService.sWanUrl)
                .addCallAdapterFactory(RxJava2CallAdapterFactory.create())
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        WanService wanService = build.create(WanService.class);
        Observable<NaviBean> navi = wanService.getNavi();
        navi.subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new Observer<NaviBean>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(NaviBean naviBean) {
                       callBack.onSuccess(naviBean);
                        Log.i("aaa", "onNext: "+naviBean.toString());
                    }

                    @Override
                    public void onError(Throwable e) {
                    callBack.onFail(e.getMessage());
                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }
}
